home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / BuildingBlocks / BuildingBlocksTest.cp < prev    next >
Encoding:
Text File  |  1995-07-28  |  2.2 KB  |  120 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        BuildingBlocksTest.cp
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef    __BUILDINGBLOCKSTEST__
  15. #include "BuildingBlocksTest.h"
  16. #endif
  17.  
  18. #ifndef    __STRING__
  19. #include "String.h"
  20. #endif
  21.  
  22. #ifndef    __TOOLUTILS__
  23. #include "ToolUtils.h"
  24. #endif
  25.  
  26. #ifndef    __STDLIB__
  27. #include "StdLib.h"
  28. #endif
  29.  
  30. #ifndef    __MEMORY__
  31. #include "Memory.h"
  32. #endif
  33.  
  34. #pragma segment BuildingBlocksTests
  35.  
  36. /***********************************|****************************************/
  37.  
  38. #ifdef    BLJTestTool
  39.  
  40.     #ifndef __CURSORCTL__
  41.     #include "CursorCtl.h"
  42.     #endif
  43.     
  44.     void Busy ( short s )
  45.     {
  46.         SpinCursor ( s );
  47.     }
  48.     
  49. #else
  50.  
  51.     void Busy ( short ) 
  52.     {
  53.     }
  54.     
  55. #endif
  56.  
  57. /***********************************|****************************************/
  58. /***********************************|****************************************/
  59.  
  60. CLeakChecker::CLeakChecker ( ostream& stream ):
  61.     fReportTo ( stream ),
  62.     fRememberedFree ( GetFreeBytes () )
  63. {
  64. }
  65.  
  66. /***********************************|****************************************/
  67.  
  68. CLeakChecker::~CLeakChecker ()
  69. {
  70.     ReportIfChanged ();
  71. }
  72.  
  73. /***********************************|****************************************/
  74.  
  75. ostream& 
  76. CLeakChecker::operator >> ( ostream& stream ) const
  77. {
  78.     return stream << "current: " << GetFreeBytes () << ", delta: " << GetDelta () << '\n';
  79. }
  80.  
  81. /***********************************|****************************************/
  82.  
  83. void
  84. CLeakChecker::ReportIfChanged ()
  85. {
  86.     long delta = GetDelta ();
  87.     
  88.     if ( delta != 0 )
  89.     {
  90.         fReportTo << "••• CLeakChecker Report: HEAP GREW BY " << delta << " BYTES!\n" << flush;
  91.     }
  92. }
  93.  
  94. /***********************************|****************************************/
  95.  
  96. void
  97. CLeakChecker::Remember ()
  98. {
  99.     fRememberedFree = GetFreeBytes ();
  100. }
  101.  
  102. /***********************************|****************************************/
  103.  
  104. unsigned long 
  105. CLeakChecker::GetFreeBytes () const
  106. {
  107.     CompactMem ( maxSize );
  108.     return FreeMem ();
  109. }
  110.  
  111. /***********************************|****************************************/
  112.  
  113. long 
  114. CLeakChecker::GetDelta () const
  115. {
  116.     return (long) fRememberedFree - (long) GetFreeBytes ();
  117. }
  118.  
  119. /***********************************|****************************************/
  120.